package com.whut.cristiano.autographbook.Model;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.whut.cristiano.autographbook.R;
import com.whut.cristiano.autographbook.Util.ImageUtil;
import com.whut.cristiano.autographbook.Util.LogUtil;
import com.whut.cristiano.autographbook.Util.NetUtil;
import com.whut.cristiano.autographbook.Util.SharedPrefUtil;
import com.whut.cristiano.autographbook.Util.ToastUtil;

import java.text.SimpleDateFormat;

/**
 * Created by ykbboom on 2017/4/12 17:50
 * email：ykbpro@whut.edu.cn
 */

public class ReplyDialog extends DialogFragment {

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        // Get the layout inflater
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.reply_dialog, null);
        final EditText editText = (EditText) view.findViewById(R.id.receive_phone);
        final EditText contentEdit = (EditText) view.findViewById(R.id.reply_content);
        final Activity activity = getActivity();
        final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        LogUtil.d("ReplyDialog",activity.getPackageName()+getArguments().getInt("cardId"));
        final ProgressDialog progressDialog = new ProgressDialog(activity);
        // Inflate and set the layout for the dialog
        // Pass null as the parent view because its going in the dialog layout
        builder.setView(view)
                // Add action buttons
                .setPositiveButton("确定",
                        new DialogInterface.OnClickListener()
                        {
                            @Override
                            public void onClick(DialogInterface dialog, int id)
                            {
                                showDialog(progressDialog);
                                String time = simpleDateFormat.format(new java.util.Date());
                                NetUtil.replyCard(contentEdit.getText().toString(),getArguments().getInt("cardId"),time,progressDialog);
                            }
                        }).setNegativeButton("取消", null);
        return builder.create();
    }
    public void showDialog(ProgressDialog progressDialog) {
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setIndeterminate(false);
        progressDialog.setCancelable(false);
        progressDialog.setMessage("正在发送消息...");
        progressDialog.show();
    }
}
